package com.zwl.swagger;

import lombok.SneakyThrows;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

/**
 * @author zhangweilin
 * @date 2021/8/27 17:32
 * @Description:
 */
@Mojo(name = "zwl-swagger", defaultPhase = LifecyclePhase.PACKAGE)
public class ZwlSwaggerMojo extends AbstractMojo {

    private static final Log log = LogFactory.getLog(ZwlSwaggerMojo.class);

    @Parameter
    private String srcPath;

    @Parameter
    private String classPath;

    @Parameter
    private boolean enable=false;

    @SneakyThrows
    @Override
    public void execute() {
        log.info("zwl-swagger-plugin.enable:" + enable);
        if (!enable) {
            return;
        }
        log.info("gen doc config file,src:" + srcPath);
        log.info("gen doc config file,classPath:" + classPath);
        try {
            CommentCollector.collector(srcPath, classPath);
        } catch (Throwable e) {
            log.error("gen doc config file error, srcPath:" + srcPath);
            e.printStackTrace();
        }
    }

}